The present invention relates to the allocation of memory in a computer at the application level. In particular, the invention relates to the allocation of memory in order to represent objects supported in an object-oriented programming environment.
The Component Object Module model (COM) is a language- and location-independent software specification. A general overview of COM and the closely related Object Linked and Embedding model (OLE) are presented below. COM and OLE are described fully in Inside OLE, by Kraig Brockschmidt, published by Microsoft Press (1995, 2d Edition), and in the references listed therein. The Brockschmidt reference is incorporated by reference. However, the Brockschmidt publication is not prior art.
As the C++ language is the object-oriented programming language currently enjoying the greatest acceptance among object-oriented programmers, this invention is described in C++. Of course, any language capable of to adhering to the COM standard can realize this invention and its benefits.
COM is a binary standard whose primary characteristic are objects and the interfaces associated with particular objects. An interface for an object is a set of functions for manipulating the object. A single object typically has several interfaces. C++ can very conveniently represent COM objects and interfaces (COM classes) with C++ classes.
The defining of a COM class proceeds in two steps: the first is the defining of the instance data of the object class. The second step is the defining of a class for each of the object class' interfaces.
Interface implementations are C++ classes derived from an abstract interface definition.
FIG. 1A schematically illustrates the layout of an example COM object 1A00, according to the conventional COM implementation. The object 1A00 contains some infrastructure, such as a pointer 1A10 to a controlling unknown interface and a reference counter 1A20. The object 1A00 also includes application data 1A30. Further, there is a pointer 1A40 for each interface which the object 1A00 supports, including the requisite IUnknown interface. (Each pointer 1A40 points directly to the vtable implementing the interface.) For each interface which the object 1A00 supports, the conventional implementation allocates a corresponding object 1A50 for the interface. This conventional and convenient implementation of COM interfaces takes advantage of C++'s virtual function capability.
However, the conventional implementation has a number of deficiencies. Objects such as sample object 1A00 are allocated and initialized at application start-up and remain in the memory of the application, despite the fact that the application may never use the object and despite the fact that, at any given time, the application will not use most objects. Therefore, the conventional implementation incurs the memory costs of one pointer 1A10 to a controlling interface, the reference counter 1A20, pointers 1A40 and one object 1A50 for each interface supported for an object.
Accordingly, a goal of this invention is the reduction of the memory costs of implementing COM objects.
Another goal of the invention is the simplification of the programming interface to COM and the elimination of a substantial amount of the repetitive infrastructure of conventional COM.
Yet another goal of the invention is to relieve individual designers of the need to devise complicated schemes to reduce memory consumption.